package com.jvm.类加载机制;

import java.lang.reflect.Method;

public class MyTest {

    public static void main(String[] args) throws Exception {
        MyClassLoaderParentFirst myClassLoaderParentFirst = new MyClassLoaderParentFirst();
        MyClassLoaderParentFirst myClassLoaderParentSecond = new MyClassLoaderParentFirst();
        Class testAClass = myClassLoaderParentFirst.findClass("com.java.loader.TestA");
        Method mainMethodA = testAClass.getDeclaredMethod("main", String[].class);
        mainMethodA.invoke(null, new Object[]{args});
        Class testBClass = myClassLoaderParentSecond.findClass("com.java.loader.TestB");
        Method mainMethodB = testBClass.getDeclaredMethod("main", String[].class);
        mainMethodB.invoke(null, new Object[]{args});

        hello hello1 = new hello2(new hello1(new hello()));
        hello1.print1();
    }

  public static class hello{
        hello parent;

        public hello() {
        }

        public hello(hello hello) {
            this.parent = hello;
        }
        public void print() {
            if (parent != null) {
                parent.print();
            }else{
                System.out.println("hello print"+parent);
            }
            print1();
        }
        public void print1() {
            System.out.println("hello"+parent);
        }
    }
    public static  class hello1 extends hello{

        hello parent;
        public hello1(hello hello) {
            this.parent = hello;
        }
        public void print() {
            if (parent != null) {
                parent.print();
            }else{
                System.out.println("hello print"+parent);
            }
            print1();
        }
        public hello1() {
        }

        public void print1() {
            System.out.println("hello1"+parent);
        }
    }
    public static  class hello2 extends hello1{
        hello parent;
        public hello2(hello hello) {
            this.parent = hello;
        }
        public void print() {
            if (parent != null) {
                parent.print();
            }else{
                System.out.println("hello print"+parent);
            }
            print1();
        }
        public void print1() {
            System.out.println("hello2"+parent);
        }
    }
}